<?php
/**
*
* Layout for the shopping cart
*
* @package	VirtueMart
* @subpackage Cart
* @author Max Milbers
*
* @link http://www.virtuemart.net
* @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
*
*/


// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

		// Added for the zone shipping module
		//$vars["zone_qty"] = 0;
		$weight_total = 0;
		$weight_subtotal = 0;

		//of course, some may argue that the $product_rows should be generated in the view.html.php, but
		//
		$product_rows = array();

		$i=0;
		foreach ($this->_cart->products as $priceKey=>$product){

			$product->category_id = $this->_cart->getCardCategoryId($product->product_id);
			/* Create product URL */
			$url = JRoute::_('index.php?option=com_MVM&format=json&view=product&product_id='.$product->product_id.'&category_id='.$product->category_id);

			/** @todo Add variants */
			$product_rows[$i]['product_name'] = $product->product_name;
			$product_rows[$i]['product_id'] = $product->product_id;
			$product_rows[$i]['quantity'] = $product->quantity;			
			$product_rows[$i]['product_sku'] = $product->product_sku;
			$product_rows[$i]['url'] = $url;
			$product_rows[$i]['product_s_desc'] = $product->product_s_desc;
			$product_rows[$i]['product_desc'] = $product->product_desc;
			$product_rows[$i]['product_thumb_image'] = $product->product_thumb_image;
			$product_rows[$i]['product_full_image'] = $product->product_full_image;
			$product_rows[$i]['product_weight'] = $product->product_weight;
			$product_rows[$i]['product_weight_uom'] = $product->product_weight_uom;
			$product_rows[$i]['product_length'] = $product->product_length;
			$product_rows[$i]['product_width'] = $product->product_width;
			$product_rows[$i]['product_height'] = $product->product_height;
			$product_rows[$i]['product_lwh_uom'] = $product->product_lwh_uom;
			$product_rows[$i]['product_in_stock'] = $product->product_in_stock;
			$product_rows[$i]['low_stock_notification'] = $product->low_stock_notification;
			$product_rows[$i]['product_available_date'] = $product->product_available_date;
			$product_rows[$i]['product_special'] = $product->product_special;
			$product_rows[$i]['ship_code_id'] = $product->ship_code_id;
			$product_rows[$i]['product_sales'] = $product->product_sales;
			
			/* Product PRICE */
			$product_rows[$i]['salesPrice'] = $this->prices[$priceKey]['salesPrice'];
			$product_rows[$i]['basePrice'] = $this->prices[$priceKey]['basePrice'];
			$product_rows[$i]['basePriceVariant'] = $this->prices[$priceKey]['basePriceVariant'];
			$product_rows[$i]['basePriceWithTax'] = $this->prices[$priceKey]['basePriceWithTax'];
			$product_rows[$i]['discountedPriceWithoutTax'] = $this->prices[$priceKey]['discountedPriceWithoutTax'];
			$product_rows[$i]['priceBeforeTax'] = $this->prices[$priceKey]['priceBeforeTax'];
			$product_rows[$i]['taxAmount'] = $this->prices[$priceKey]['taxAmount'];
			$product_rows[$i]['discountAmount'] = $this->prices[$priceKey]['discountAmount'];
			$product_rows[$i]['priceWithoutTax'] = $this->prices[$priceKey]['priceWithoutTax'];
			/* subtotals take into consideration quantity */
			$product_rows[$i]['subtotal'] = $this->prices[$priceKey]['subtotal'];
			$product_rows[$i]['subtotal_tax_amount'] = $this->prices[$priceKey]['subtotal_tax_amount'];
			$product_rows[$i]['subtotal_discount'] = $this->prices[$priceKey]['subtotal_discount'];
			$product_rows[$i]['subtotal_with_tax'] = $this->prices[$priceKey]['subtotal_with_tax'];
			$product_rows[$i]['vendorCurrency'] = $this->prices['currency'];
			
			

			$i++;
		} // End of for loop through the Cart


		?>
{
"userName" : <?php echo json_encode($this->userName); ?>,
"cart" :
	{
		"cart_url" : <?php echo json_encode(JURI::root() . 'index.php?option=com_mvm&task=cart.cart&view=cart&format=json'); ?>,
		"products" : [
<?php $i=0; foreach( $product_rows as $prow ) { ?>
			{
			"name" : <?php echo json_encode($prow["product_name"].$prow["customfieldsCart"]); ?>,
			"id" : <?php echo json_encode($prow["product_id"]); ?>,
			"desc" : <?php echo json_encode($prow["product_desc"]);?>,
			"short_desc" : <?php echo json_encode($prow["product_s_desc"]) ?>,
			"image_url" : <?php echo json_encode(JURI::root().IMAGEURL."product/".$prow["product_full_image"]); ?>,
			"image_url_thumb" : <?php echo json_encode(JURI::root().IMAGEURL."product/".$prow["product_thumb_image"]); ?>,
			"image_filename" : <?php echo json_encode( $prow["product_full_image"]);?>,
			"image_filename_thumb" : <?php echo json_encode($prow["product_thumb_image"]);?>,
			"quantity" : <?php echo json_encode($prow["quantity"]);?>,			
			"product_sku" : <?php echo json_encode($prow["product_sku"]); ?>,
			
			"salesPrice" : <?php echo json_encode($prow["salesPrice"]); ?>,
			"basePrice" : <?php echo json_encode($prow["basePrice"]); ?>,
			"basePriceVariant" : <?php echo json_encode($prow["basePriceVariant"]); ?>,
			"basePriceWithTax" : <?php echo json_encode($prow["basePriceWithTax"]); ?>,
			"discountedPriceWithoutTax" : <?php echo json_encode($prow["discountedPriceWithoutTax"]); ?>,
			"priceBeforeTax" : <?php echo json_encode($prow["priceBeforeTax"]); ?>,
			"taxAmount" : <?php echo json_encode($prow["taxAmount"]); ?>,
			"discountAmount" : <?php echo json_encode($prow["discountAmount"]); ?>,
			"priceWithoutTax" : <?php echo json_encode($prow["priceWithoutTax"]); ?>,
			"subtotal" : <?php echo json_encode($prow["subtotal"]); ?>,
			"subtotal_tax_amount" : <?php echo json_encode($prow["subtotal_tax_amount"]); ?>,
			"subtotal_discount" : <?php echo json_encode($prow["subtotal_discount"]); ?>,
			"sobtotal_with_tax" : <?php echo json_encode($prow["subtotal_with_tax"]); ?>,
		    "currency": <?php echo json_encode($product_rows[$i]["vendorCurrency"])?>,
			"remove_from_basket_url" : <?php echo json_encode(JURI::root().'?option=com_mvm&task=cart.delete&view=cart&format=json&product_id='. $prow["product_id"]);?>
		    
			
			
			} <?php $i++; if($i < count($product_rows)) echo (",");?>
			
<?php } ?>
		],
		"basePrice" : <?php echo json_encode($this->prices["basePrice"]); ?>,
		"basePriceWithTax" : <?php echo json_encode($this->prices["basePriceWithTax"]); ?>,
		"discountedPriceWithoutTax" : <?php echo json_encode($this->prices["discountedPriceWithoutTax"]); ?>,
		"taxAmount" : <?php echo json_encode($this->prices["taxAmount"]); ?>,
		"discountAmount" : <?php echo json_encode($this->prices["discountAmount"]); ?>,
		"priceWithoutTax" : <?php echo json_encode($this->prices["priceWithoutTax"]); ?>,
		"salesPrice" : <?php echo json_encode($this->prices["salesPrice"]); ?>,

		"edit_shipping_url" : <?php echo json_encode( JRoute::_("index.php?option=com_mvm&format=json&task=cart.edit_shipping"));?>,
		"shippingName" : <?php echo json_encode( $this->cartData["shippingName"]); ?>,
		"shippingValue" : <?php echo json_encode( $this->prices["shippingValue"]); ?>,
		"shippingTax" : <?php echo json_encode( $this->prices["shippingTax"]); ?>,
		"salesPriceShipping" : <?php echo json_encode( $this->prices["salesPriceShipping"]); ?>,
		"edit_payment_url" :<?php echo json_encode( JRoute::_("index.php?option=com_mvm&format=json&task=cart.editpayment")); ?>,
		"paymentName" : <?php echo json_encode( $this->cartData["paymentName"]); ?>,
		"paymentVal" : <?php echo json_encode( $this->prices["paymentValue"]); ?>,
		"paymentTax" : <?php echo json_encode( $this->prices["paymentTax"]); ?>,
		"paymentDiscount" : <?php echo json_encode( $this->prices["paymentDiscount"]); ?>,

		"billSub" :  <?php echo json_encode( $this->prices["billSub"]); ?>,
		"billTaxAmount" : <?php echo json_encode( $this->prices["billTaxAmount"]); ?>,
		"billDiscountAmount" : <?php echo json_encode( $this->prices["billDiscountAmount"]); ?>, 
		"billTotal" : <?php echo json_encode( $this->prices["billTotal"]); ?>,	
		"vendor_currency" : <?php echo json_encode( $this->prices["currency"]);?>,
		
		"shipping_rate_id" : <?php echo json_encode($this->shipping_rate_id); ?>,
	<?php include(JPATH_COMPONENT.DS."views".DS."cart".DS."tmpl".DS."shippment.php");?>
		
	}
}		

